package ${groupId};

import java.util.Date;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class DataHelper {
	public static void createRegistration(Registration reg) {
		try {
			reg.setInsertDate((new Date()).toString());
	        Session session = getSession();
	        Transaction transaction = session.beginTransaction();
	        session.save(reg);
	        transaction.commit();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	public static List<Registration> getRegistrations() {
		Session session = getSession();
        session.beginTransaction();    
        List<Registration> registrations = session.createQuery("from Registration").list();
        session.getTransaction().commit();
		return registrations;
	}
	
	private static Session getSession() {
		return HibernateUtil.getSessionFactory().getCurrentSession();
	}
	
}
